#pragma once
//#include "stdafx.h"
#include "CircleNode.h"
#include "Agent.h"
#include "Vector.h"
#include "Space.h"
#include "SpaceNode.h"
namespace org
{
	namespace spark
	{
		namespace space
		{
			using org::spark::math::Vector;
			using org::spark::space::Space;
			using org::spark::space::SpaceNode;
			CircleNode::CircleNode(Space *space, double radius)
				:SpaceNode(space)
			{

						//		if (radius <= 0.0)
						//			radius = 1.0;

				this->radius = radius;
			}

			void CircleNode::setRadius(double r)
			{
				if (r > space::maximumNodeRadius)
					space->maximumNodeRadius = r;
					

				radius = r;
			}

			void CircleNode::setRadius0(double r)
			{
				radius = r;
			}

			bool CircleNode::intersects(SpaceNode *node)
			{
				if (node->space != space)
					return false;

				return node->intersectsWith(this);
			}

			double CircleNode::getRelativeSize()
			{
				return radius;
			}

			int CircleNode::getShape()
			{
				return SpaceAgent::CIRCLE;
			}

			bool CircleNode::intersectsWith(CircleNode *circle)
			{
				Vector *v = space::getVector(position, circle->position);

				double d = radius + circle->radius;
				if (d*d > v->lengthSquared())
					return true;

				return false;
			}

			bool CircleNode::intersectsWith(Square2Node *node)
			{
				return node->intersectsWith(this);
			}

			bool CircleNode::intersectsWith(SquareNode *node)
			{
				return intersectsWith(static_cast<CircleNode*>(node));
			}
		}
	}
}
